import Components from 'unplugin-vue-components/vite';
import {r} from "../shared/path.js";
import {detectResolvers} from "../shared/detect.js";

import {
    AntDesignVueResolver,
    ArcoResolver,
    DevUiResolver,
    ElementPlusResolver,
    HeadlessUiResolver,
    IduxResolver,
    InklineResolver,
    LayuiVueResolver,
    NaiveUiResolver,
    PrimeVueResolver,
    QuasarResolver,
    TDesignResolver,
    VantResolver,
    VarletUIResolver,
    ViewUiResolver,
    VueUseComponentsResolver,
    Vuetify3Resolver,
} from 'unplugin-vue-components/resolvers'

// 按需自动加载组件的 Vite 插件
// unplugin-vue-components/vite
export default function createComponentsAutoImport() {
    return Components({
        directoryAsNamespace: true,
        include: [/\.vue$/, /\.vue\?vue/, /\.[tj]sx$/, /\.md$/],
        extensions: ['md', 'vue', 'tsx', 'jsx'],
        dts: r('presets/types/components.d.ts'),
        types: [
            {
                from: 'vue-router',
                names: ['RouterLink', 'RouterView'],
            },
        ],
        resolvers: detectResolvers({
            onlyExist: [
                [VantResolver(), 'vant'],
                [QuasarResolver(), 'quasar'],
                [DevUiResolver(), 'vue-devui'],
                [NaiveUiResolver(), 'naive-ui'],
                [Vuetify3Resolver(), 'vuetify'],
                [PrimeVueResolver(), 'primevue'],
                [ViewUiResolver(), 'view-design'],
                [LayuiVueResolver(), 'layui-vue'],
                [VarletUIResolver(), '@varlet/ui'],
                [IduxResolver(), '@idux/components'],
                [InklineResolver(), '@inkline/inkline'],
                [ElementPlusResolver(), 'element-plus'],
                [HeadlessUiResolver(), '@headlessui/vue'],
                [ArcoResolver(), '@arco-design/web-vue'],
                [AntDesignVueResolver({importStyle: false}), 'ant-design-vue'],
                [VueUseComponentsResolver(), '@vueuse/components'],
                [TDesignResolver({library: 'vue-next'}), 'tdesign-vue-next'],
            ],
        }),
    })
}